﻿using System;
using System.Data;

namespace wuliuback
{
    public partial class CheckLogin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string userName = Request["user_id"];
            string password = Request["password"];
            string type = Request["type"];

            string code = "";
            string msg = "";

            
            if (userName == null || userName.Length <= 0 || password == null || password.Length <= 0)
            {
                code = "-1";
                msg = "用户名或密码为空";
                Response.Output.WriteLine("{\"code\":\"" + code + "\",\"msg\":\"" + msg + "\"}");
                return;
            }
            string mdtPw = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5").ToLower().Substring(8, 16);
            String sql = "";
            if (type == "1")
            {
                sql = "select * from t_user where user_id='" + userName + "' and password='" + mdtPw + "'";
                code = "-1";
            }
            else
            {
                sql = "select * from t_user where mobile='" + userName + "' and password='" + mdtPw + "'";
                code = "-2";
            }
            DbHelper dbHelper=new DbHelper();
            DataSet dataSet = dbHelper.Select(sql);
            DataTable table=dataSet.Tables[0];
            if (table.Rows.Count <= 0)
            {
                code = "-1";
                msg = "登陆失败";
            }
            else
            {
                code = "0";
                msg = "登陆成功";
            }
            Response.Output.WriteLine("{\"code\":\""+code+"\",\"msg\":\""+msg+"\"}");
        }
    }
}
